package com.itheima.edu.info.manager.util;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class LoginStudnetProp {
    //学生管理系统登录功能实现
    public static boolean login() {
        boolean flag = false;
        FileReader fr = null;
        try {
            Scanner sc = new Scanner(System.in);
            Properties prop = new Properties();
            fr = new FileReader("黑马学生管理系统3\\prop.properties");
            prop.load(fr);
            System.out.println("请输入用户名: ");
            String username = sc.next();
            System.out.println("请输入密码名: ");
            String password = sc.next();
            String pass = prop.getProperty(username);
            if (pass != null && password.equals(pass)) {
                System.out.println("恭喜您,登录成功....");
                System.out.println("=========================================================");
                flag = true;
            } else {
                System.out.println("用户名或密码不正确........");
            }
        } catch (IOException e) {
            //e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                    //e.printStackTrace();
                }
            }
            return flag;
        }
    }

    //学生管理系统登录功能实现2
    public static boolean login2() {
        boolean flag = false;
        FileReader fr = null;
        try {
            Scanner sc = new Scanner(System.in);
            Properties prop = new Properties();
            fr = new FileReader("黑马学生管理系统3\\prop.properties");
            prop.load(fr);
            System.out.println("请输入用户名: ");
            String username = sc.next();
            System.out.println("请输入密码名: ");
            String password = sc.next();
            String pass = prop.getProperty(username);
            if (pass != null && password.equals(pass)) {
                System.out.println("恭喜您,登录成功....");
                System.out.println("=========================================================");
                flag = true;
            } else {
                System.out.println("用户名或密码不正确........");
            }
        } catch (IOException e) {
            //e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                    //e.printStackTrace();
                }
            }
            return flag;
        }
    }
}
